Component({
  /**
   * 页面的初始数据
   */
  properties: {
    coupon: {
      type: Object,
      value: 'default value'
    },
    couponType: { //优惠券样式类型
      type: String,
      value: 'myCoupon'
    },
    passParams: String
  },
  data: {
    detail: false, //是否处于详情页
    starttime: [],
    endtime: [],
    detailBtn: true//是否需要详情页按钮
  },
  ready: function() {
    let pageObj = getCurrentPages()
    var route = pageObj.pop().__route__
    if (route.indexOf("couponsDetail/couponsDetail") > -1) {
      this.setData({
        detail: true
      });
    }
    console.log(222, this.properties.coupon.createTime)
    console.log(15155,this.properties.coupon);
    //  let date = []
    // let date1 = this.properties.coupon.createTime.replace(/-/g, '.')
    // date1 = date1.substr(0, date1.length - 8)

    // let date2 = this.properties.coupon.expireDate.replace(/-/g, '.')

    //  this.setData({
    //    starttime:date1,
    //    endtime:date2
    //  })
    //  console.log(this.data.date1)
  },
  /**
   * 组件的方法列表
   */
  methods: {
    initData: function() {
      var pages = getCurrentPages() //获取加载的页面
      var currentPage = pages[pages.length - 1] //获取当前页面的对象
      var url = currentPage.route //当前页面ur
      console.log(url, '-------------url---------------')
    },
    // 去优惠券详情
    goCouponDetail: function(e) {
      let pageObj = getCurrentPages()
      var route = pageObj.pop().__route__
      if (route.indexOf('couponsDetail') == -1) { // 不在详情页
        let id = e.currentTarget.dataset.id
        // wx.setStorageSync('dqcoupon', this.properties.coupon)
        wx.navigateTo({
          url: '/subPackages2/pages/my/myCoupons/couponsDetail/couponsDetail?id=' + id + '&pageType=' + this.data.couponType
        })
      } else {
        let id = e.currentTarget.dataset.id
        // wx.setStorageSync('dqcoupon', this.properties.coupon)
        wx.navigateTo({
          url: '/subPackages2/pages/my/myCoupons/couponsDetail/couponsDetail?id=' + id + '&pageType=' + this.data.couponType
        })
      }
    },
    goCouponRules: function(e) {
      let id = e.currentTarget.dataset.id // 优惠券活动id
      // wx.setStorageSync('dqcoupon', this.properties.coupon)
      wx.navigateTo({
        url: '/subPackages2/pages/my/myCoupons/couponsRules/couponsRules?id=' + id
      })
    },
    // 跳转优惠券转赠页面
    goCouponExamples: function(e) {
      let pageObj = getCurrentPages()
      var route = pageObj.pop().__route__
      if (route.indexOf('couponsExamples') == -1) { // 不在赠送页
        let id = e.currentTarget.dataset.id
        // wx.setStorageSync('dqcoupon', this.properties.coupon)
        wx.navigateTo({
          url: '/subPackages2/pages/my/myCoupons/couponsExamples/couponsExamples?id=' + id
        })
      }
    },
    // 立即领取
    receive: function(e) {
      console.log(this.properties)
//       debugger
//       accountDayLimit: 1
// accountLimit: 1
// amount: 0.88
// bgImgs: ""
// circulation: 8
// couponsConfigId: "1173865617778630656"
// createPerson: "admin"
// createTime: "2019-09-17 15:45:47"
// currentCirculation: 5
// expireDate: "2019-09-24"
// name: "8.88"
// offlineTime: "2019-09-23 15:45:08"
// onlineTime: "2019-09-17 15:45:03"
// productId: "1058559242854629376"
// remark: "先到先得，数量有限"
// scene: 1
// startTime: "2019-09-17"
// status: 0
// type: 2
      let id = e.currentTarget.dataset.id;
      let {amount,name,type}=this.properties.coupon
      var myEventDetail = {
        id,
        amount,
        name,
        type
      } // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
    }
  }
})
